//订单
var invoice = {
	id:"",
	orderNum:""
};


//订单详情
invoice.detail = function(){
	var args = getQueryStringArgs();
	invoice.orderNum = args["orderNum"];
	var ajax = new $ax(Feng.ctxPath+"/order/getById", function(data){
        Feng.log("查询详情成功");
        if (data.success){
			 var outHtml = template("personalTempl",data.obj);
    		$("#personalMain").html(outHtml);
    		 var outHtml = template("companyTempl",data.obj);
    		$("#companyMain").html(outHtml);

        }
    },function(data){
        Feng.error("查询详情失败!");
    });
    ajax.set("id",invoice.id);
    ajax.start();
}




//个人发票信息提交
invoice.submitInfo = function(){
//	var userFrom = getFormJson("#personalMain");
	var args = getQueryStringArgs();
	var invoiceType = $(".tab-nav .tab-nav-item.tab-active").index()+1;
	var options = {};
	
	if(invoiceType === 1){
		options = getFormJson("#personalMain");
	}
	else{
		options = getFormJson("#companyMain");	
	}
	options.invoiceType = invoiceType;
	options.userId = Feng.userId;
	options.orderNum = args["orderNum"];

	if(options.invoiceTitle === ""){
		Feng.error("请输入发票抬头");
		return;
	}

	if(invoiceType === 2 && options.taxCode === ""){
		Feng.error("请输入税务号");
		return;
	}


	var ajax = new $ax(Feng.ctxPath+"/invoice/invoiceApply", function(data){        
        if (data.success){
        	Feng.success("提交成功");
    		setTimeout(function(){
    			window.location.href = "my-invoice.html";
    		},"2000");
        }
        else if(data.code === 2){
        	Feng.error(data.msg);
        }
        else{
        	Feng.log("提交用户信息失败");
        }        
   },function(data){    	
        Feng.log("提交用户信息失败");
    });
    ajax.set(options);
    ajax.start();
};
//公司发票信息提交
invoice.submitComp = function(){
	var orderNum = $("#orderNum1").val();
	var userId = $("#userId1").val();
	var invoiceType = $("#invoiceType1").val();
	var invoiceTitle = $("#invoiceTitle1").val();
	var taxCode = $("#taxCode").val();
	var email = $("#email1").val();
	var phone = $("#phone1").val();
	var unitAddress = $("#unitAddress").val();
	var bank = $("#bank").val();
	var bankAccount = $("#bankAccount").val();
	var options = {
			orderNum:orderNum,
			userId:userId,
			invoiceType:invoiceType,
			taxCode:taxCode,
			email:email,
			phone:phone,
			invoiceTitle:invoiceTitle,
			unitAddress:unitAddress,
			bank:bank,
			bankAccount:bankAccount
			
		};
	var ajax = new $ax(Feng.ctxPath+"/invoice/invoiceApply", function(data){        
        if (data.success){
        	if(data.obj===null){
				Feng.success("提交成功");
        	
        	}
        	else{   		
        	}    	
        }
        else if(data.code === 2){
        	Feng.error(data.msg);
        }
        else{
        	Feng.log("提交用户信息失败");
        }        
   },function(data){    	
        Feng.log("提交用户信息失败");
    });
    ajax.set(options);
    ajax.start();
};

$(function(){	
	invoice.detail();	
//	product.carLength();
});

/**
 * Javascript API调用Tab
 */
!function ($) {
    var $tab = $('#J_Tab');

    $tab.tab({
        nav: '.tab-nav-item',
        panel: '.tab-panel-item',
        activeClass: 'tab-active'
    });

 

    $tab.find('.tab-nav-item').on('opened.ydui.tab', function (e) {
        console.log('索引：%s - [%s]已经打开了', e.index, $(this).text());
    });
}(jQuery);